344C - Rational Resistance - CodeForces Solution


math number theory *1600

Please click on ads to support us..

Python Code:

def rec(s,t):
  if s==0 or t==0:
    return 0
  if (t>s):
    return rec(t,s)
  return s//t + rec(s%t,t)

s,t = map(int,input().split())
res = rec(s,t)
print(res)

C++ Code:

// Online C++ compiler to run C++ program online
#include <bits/stdc++.h>
using namespace std;




int main() {
    long long a,b;
    cin >> a >> b;
   
    
    long long res = 0;
    while(a && b){
        res += a/b;
        a =a %b;
        swap(a,b);
        
    }
    
    cout << res << endl;
    
}


Comments

Submit
0 Comments
More Questions

Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making